// *********************************************************
//      Copyright (c) Kosta Gaitanis
//      All rights reserved
//
//      k.gaitanis@gmail.com
//
// *********************************************************

#include "Rectangle.h"
#include "Cylinder.h"
#include "Car.h"

Car::Car() :
    Item("Car")
{
    Item* chassis = new Rectangle(2, 4, 1, "Chassis");
    Item* cubicle = new Rectangle(2, 2, 0.4, "Cubicle");
    Item* wheelFL = new Cylinder(0.5, 0.2, "Front Left Wheel");
    Item* wheelFR = new Cylinder(0.5, 0.2, "Front Right Wheel");
    Item* wheelBL = new Cylinder(0.5, 0.2, "Back Left Wheel");
    Item* wheelBR = new Cylinder(0.5, 0.2, "Back Right Wheel");

    cubicle->setTransform(Matrix::translation(0,0,0.7));
    wheelBL->setTransform(Matrix::translation(-1, -2, 0) * Matrix::rotationY(M_PI_2));
    wheelBR->setTransform(Matrix::translation(1, -2, 0) * Matrix::rotationY(M_PI_2));
    wheelFL->setTransform(Matrix::translation(-1, 2, 0) * Matrix::rotationY(M_PI_2));
    wheelFR->setTransform(Matrix::translation(1, 2, 0) * Matrix::rotationY(M_PI_2));

    chassis->addChild(cubicle);
    chassis->addChild(wheelBL);
    chassis->addChild(wheelBR);
    chassis->addChild(wheelFL);
    chassis->addChild(wheelFR);
    addChild(chassis);
}

void Car::onFrameChanged(double frame)
{
    setTransform(Matrix::rotationX(frame/100.0));
}

